package com.rocpenghua.excel.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * 测试类
 */
public class TextMain {
    public static void main(String[] args) throws Exception {
//        单级的表头
        Map<String, String> map = new HashMap<String, String>();
        map.put("登录名", "u_login_id");
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("用户名", "u_name");
        Map<String, String> map2 = new HashMap<String, String>();
        map2.put("角色", "u_role");
        Map<String, String> map3 = new HashMap<String, String>();
        map3.put("部门", "u_dep");//d_name
        Map<String, String> map4 = new HashMap<String, String>();
        map4.put("用户类型", "u_type");
        List<Map<String, String>> titleList = new ArrayList<>();
        titleList.add(map);
        titleList.add(map1);
        titleList.add(map2);
        titleList.add(map3);
        titleList.add(map4);
        //单级的 行内数据
        List<Map<String, String>> rowList = new ArrayList<>();
        for (int i = 0; i < 7; i++) {
            Map m = new HashMap<String, String>();
            m.put("u_login_id", "登录名" + i);
            m.put("u_name", "张三" + i);
            m.put("u_role", "角色" + i);
            m.put("u_dep", "部门" + i);
            m.put("u_type", "用户类型" + i);
            rowList.add(m);
        }

        String name = UUID.randomUUID().toString();
        ExcelTool excelTool = new HssfExcelTool("单级表头的表格", 20, 20);
        List<Column> titleData = excelTool.columnTransformer(titleList);
        long start = System.currentTimeMillis();
        excelTool.exportExcel(titleData, rowList, "e://" + name + ".xls", true, false);
        System.out.println(System.currentTimeMillis() - start);

        excelTool = new XssfExcelTool("单级表头的表格", 20, 20);
        start = System.currentTimeMillis();
        excelTool.exportExcel(titleData, rowList, "e://" + name + ".xlsx", true, false);
        System.out.println(System.currentTimeMillis() - start);


        //List<Map>数据 多级表头,数据如下:
        //        登录名  姓名       aa
        //                      角色    部门
        titleList = new ArrayList<>();
        Map<String, String> titleMap = new HashMap<String, String>();
        titleMap.put("id", "11");
        titleMap.put("pid", "0");
        titleMap.put("content", "登录名");
        titleMap.put("fileName", "u_login_id");
        Map<String, String> titleMap1 = new HashMap<String, String>();
        titleMap1.put("id", "1");
        titleMap1.put("pid", "0");
        titleMap1.put("content", "姓名");
        titleMap1.put("fileName", "u_name");
        Map<String, String> titleMap2 = new HashMap<String, String>();
        titleMap2.put("id", "2");
        titleMap2.put("pid", "0");
        titleMap2.put("content", "角色加部门");
        titleMap2.put("fileName", null);
        Map<String, String> titleMap3 = new HashMap<String, String>();
        titleMap3.put("id", "3");
        titleMap3.put("pid", "2");
        titleMap3.put("content", "角色");
        titleMap3.put("fileName", "u_role");
        Map<String, String> titleMap4 = new HashMap<String, String>();
        titleMap4.put("id", "4");
        titleMap4.put("pid", "2");
        titleMap4.put("content", "部门");
        titleMap4.put("fileName", "u_dep");
        Map<String, String> titleMap5 = new HashMap<String, String>();
        titleMap5.put("id", "22");
        titleMap5.put("pid", "0");
        titleMap5.put("content", "角色加部门1");
        titleMap5.put("fileName", null);
        Map<String, String> titleMap6 = new HashMap<String, String>();
        titleMap6.put("id", "22_1");
        titleMap6.put("pid", "22");
        titleMap6.put("content", "角色1");
        titleMap6.put("fileName", "u_role");
        Map<String, String> titleMap7 = new HashMap<String, String>();
        titleMap7.put("id", "22_2");
        titleMap7.put("pid", "22");
        titleMap7.put("content", "部门1");
        titleMap7.put("fileName", "u_dep");
        titleList.add(titleMap);
        titleList.add(titleMap1);
        titleList.add(titleMap2);
        titleList.add(titleMap3);
        titleList.add(titleMap4);
        titleList.add(titleMap5);
        titleList.add(titleMap6);
        titleList.add(titleMap7);
        // 单级的 行内数据
        rowList = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Map m = new HashMap<String, String>();
            m.put("u_login_id", "登录名" + i);
            m.put("u_name", "张三" + i);
            m.put("u_role", "角色" + i);
            m.put("u_dep", "部门" + i);
            m.put("u_type", "用户类型" + i);
            rowList.add(m);
        }
        name = UUID.randomUUID().toString();
        excelTool = new HssfExcelTool("List<Map>数据 多级表头表格", 20, 20);
        titleData = excelTool.columnTransformer(titleList, "id", "pid", "content", "fileName", "0");
        start = System.currentTimeMillis();
        excelTool.exportExcel(titleData, rowList, "e://" + name + ".xls", true, false);
        System.out.println(System.currentTimeMillis() - start);

        excelTool = new XssfExcelTool("单级表头的表格", 20, 20);
        start = System.currentTimeMillis();
        excelTool.exportExcel(titleData, rowList, "e://" + name + ".xlsx", true, false);
        System.out.println(System.currentTimeMillis() - start);

        //实体类（entity）数据 多级表头,数据如下:
        List<TitleEntity> titleList1 = new ArrayList<>();
        TitleEntity titleEntity0 = new TitleEntity("title", null, "2020年05月份营销稽查业务开展成效统计表表", null);
        TitleEntity titleEntity = new TitleEntity("unit", "title", "单位：万元、万千瓦时、户、户次、人次、项次", null);
        TitleEntity titleEntity1 = new TitleEntity("0", "unit", "单位", "orgName");
        TitleEntity titleEntity2 = new TitleEntity("1", "unit", "纠正电价电费错误", null);
        TitleEntity titleEntity3 = new TitleEntity("10", "1", "追补", null);
        TitleEntity titleEntity4 = new TitleEntity("11", "1", "退减", null);
        TitleEntity titleEntity5 = new TitleEntity("12", "1", "调高力率执行标准", null);
        TitleEntity titleEntity6 = new TitleEntity("13", "1", "调整分时电价执行", null);
        TitleEntity titleEntity7 = new TitleEntity("100", "10", "户数", "consNum0101");
        TitleEntity titleEntity8 = new TitleEntity("101", "10", "电量", "effectPq0101");
        TitleEntity titleEntity9 = new TitleEntity("102", "10", "电费", "effectAmt0101");
        TitleEntity titleEntity10 = new TitleEntity("110", "11", "户数", "consNum0102");
        TitleEntity titleEntity11 = new TitleEntity("111", "11", "电量", "effectPq0102");
        TitleEntity titleEntity12 = new TitleEntity("112", "11", "电费", "effectAmt0102");
        TitleEntity titleEntity13 = new TitleEntity("120", "12", "户数", "consNum0103");
        TitleEntity titleEntity14 = new TitleEntity("121", "12", "预计年增收", "expectedAddAmt0103");
        TitleEntity titleEntity15 = new TitleEntity("130", "13", "户数", "consNum0104");
        TitleEntity titleEntity16 = new TitleEntity("131", "13", "预计年增收", "expectedAddAmt0104");

        TitleEntity titleEntity17 = new TitleEntity("2", "unit", "纠正变线损加收", null);
        TitleEntity titleEntity18 = new TitleEntity("20", "2", "加收", null);
        TitleEntity titleEntity19 = new TitleEntity("21", "2", "减收", null);
        TitleEntity titleEntity20 = new TitleEntity("200", "20", "户数", "consNum0205");
        TitleEntity titleEntity21 = new TitleEntity("201", "20", "电量", "effectPq0205");
        TitleEntity titleEntity22 = new TitleEntity("202", "20", "电费", "effectAmt0205");
        TitleEntity titleEntity23 = new TitleEntity("210", "21", "户数", "consNum0206");
        TitleEntity titleEntity24 = new TitleEntity("211", "21", "电量", "effectPq0206");
        TitleEntity titleEntity25 = new TitleEntity("212", "21", "电费", "effectAmt0206");
        titleList1.add(titleEntity0);
        titleList1.add(titleEntity);
        titleList1.add(titleEntity1);
        titleList1.add(titleEntity2);
        titleList1.add(titleEntity3);
        titleList1.add(titleEntity4);
        titleList1.add(titleEntity5);
        titleList1.add(titleEntity6);
        titleList1.add(titleEntity7);
        titleList1.add(titleEntity8);
        titleList1.add(titleEntity9);
        titleList1.add(titleEntity10);
        titleList1.add(titleEntity11);
        titleList1.add(titleEntity12);
        titleList1.add(titleEntity13);
        titleList1.add(titleEntity14);
        titleList1.add(titleEntity15);
        titleList1.add(titleEntity16);
        titleList1.add(titleEntity17);
        titleList1.add(titleEntity18);
        titleList1.add(titleEntity19);
        titleList1.add(titleEntity20);
        titleList1.add(titleEntity21);
        titleList1.add(titleEntity22);
        titleList1.add(titleEntity23);
        titleList1.add(titleEntity24);
        titleList1.add(titleEntity25);

        TitleEntity t = null;
        t = new TitleEntity("3", "unit", "纠正抄核收差错", null);
        titleList1.add(t);
        t = new TitleEntity("30", "3", "追补", null);
        titleList1.add(t);
        t = new TitleEntity("31", "3", "退减", null);
        titleList1.add(t);
        t = new TitleEntity("300", "30", "户数", "consNum0301");
        titleList1.add(t);
        t = new TitleEntity("301", "30", "电量", "effectPq0301");
        titleList1.add(t);
        t = new TitleEntity("302", "30", "电费", "effectAmt0301");
        titleList1.add(t);
        t = new TitleEntity("310", "31", "户数", "consNum0302");
        titleList1.add(t);
        t = new TitleEntity("311", "31", "电量", "effectPq0302");
        titleList1.add(t);
        t = new TitleEntity("312", "31", "电费", "effectAmt0302");
        titleList1.add(t);
        t = new TitleEntity("4", "unit", "纠正临时接电费收取", null);
        titleList1.add(t);
        t = new TitleEntity("40", "4", "追补", null);
        titleList1.add(t);
        t = new TitleEntity("41", "4", "退费", null);
        titleList1.add(t);
        t = new TitleEntity("400", "40", "笔数", "effectCnt0401");
        titleList1.add(t);
        t = new TitleEntity("401", "40", "金额", "acctAmt0401");
        titleList1.add(t);
        t = new TitleEntity("410", "41", "笔数", "effectCnt0407");
        titleList1.add(t);
        t = new TitleEntity("411", "41", "金额", "acctAmt0407");
        titleList1.add(t);
        t = new TitleEntity("5", "unit", "纠正电费滞纳金收取", null);
        titleList1.add(t);
        t = new TitleEntity("50", "5", "追补", null);
        titleList1.add(t);
        t = new TitleEntity("51", "5", "退费", null);
        titleList1.add(t);
        t = new TitleEntity("500", "50", "笔数", "effectCnt0501");
        titleList1.add(t);
        t = new TitleEntity("501", "50", "金额", "acctAmt0501");
        titleList1.add(t);
        t = new TitleEntity("510", "51", "笔数", "effectCnt0507");
        titleList1.add(t);
        t = new TitleEntity("511", "51", "金额", "acctAmt0507");
        titleList1.add(t);
        t = new TitleEntity("6", "unit", "纠正高可靠性供电费收取", null);
        titleList1.add(t);
        t = new TitleEntity("60", "6", "追补", null);
        titleList1.add(t);
        t = new TitleEntity("61", "6", "退费", null);
        titleList1.add(t);
        t = new TitleEntity("600", "60", "笔数", "effectCnt0601");
        titleList1.add(t);
        t = new TitleEntity("601", "60", "金额", "acctAmt0601");
        titleList1.add(t);
        t = new TitleEntity("610", "61", "笔数", "effectCnt0607");
        titleList1.add(t);
        t = new TitleEntity("611", "61", "金额", "acctAmt0607");
        titleList1.add(t);
        t = new TitleEntity("7", "unit", "纠正有偿服务费收取", null);
        titleList1.add(t);
        t = new TitleEntity("70", "7", "追补", null);
        titleList1.add(t);
        t = new TitleEntity("71", "7", "退费", null);
        titleList1.add(t);
        t = new TitleEntity("700", "70", "笔数", "effectCnt0701");
        titleList1.add(t);
        t = new TitleEntity("701", "70", "金额", "acctAmt0701");
        titleList1.add(t);
        t = new TitleEntity("710", "71", "笔数", "effectCnt0707");
        titleList1.add(t);
        t = new TitleEntity("711", "71", "金额", "acctAmt0707");
        titleList1.add(t);
        t = new TitleEntity("8", "unit", "调整用电结构", null);
        titleList1.add(t);
        t = new TitleEntity("80", "8", "调高单价", null);
        titleList1.add(t);
        t = new TitleEntity("81", "8", "调低单价", null);
        titleList1.add(t);
        t = new TitleEntity("800", "80", "户数", "consNum0808");
        titleList1.add(t);
        t = new TitleEntity("801", "80", "年增加电费", "yearAddAmt0808");
        titleList1.add(t);
        t = new TitleEntity("810", "81", "户数", "consNum0809");
        titleList1.add(t);
        t = new TitleEntity("811", "81", "年减少电费", "yearLossAmt0809");
        titleList1.add(t);
        t = new TitleEntity("9", "unit", "纠正计量装置异常", null);
        titleList1.add(t);
        t = new TitleEntity("90", "9", "追补", null);
        titleList1.add(t);
        t = new TitleEntity("91", "9", "退减", null);
        titleList1.add(t);
        t = new TitleEntity("900", "90", "户数", "consNum0901");
        titleList1.add(t);
        t = new TitleEntity("901", "90", "电量", "effectPq0901");
        titleList1.add(t);
        t = new TitleEntity("902", "90", "电费", "effectAmt0901");
        titleList1.add(t);
        t = new TitleEntity("910", "91", "户数", "consNum0902");
        titleList1.add(t);
        t = new TitleEntity("911", "91", "电量", "effectPq0902");
        titleList1.add(t);
        t = new TitleEntity("912", "91", "电费", "effectAmt0902");
        titleList1.add(t);
        //单级的 行内数据
        rowList = new ArrayList<>();
        for (int i = 0; i < 50000; i++) {
            Map m = new HashMap<String, String>();
            m.put("orgName", i);
            m.put("consNum0101", i);
            m.put("effectPq0101", i);
            m.put("effectAmt0101", i);
            m.put("consNum0102", i);
            m.put("effectPq0102", i);
            m.put("effectAmt0102", i);
            m.put("consNum0103", i);
            m.put("expectedAddAmt0103", i);
            m.put("consNum0104", i);
            m.put("expectedAddAmt0104", i);
            m.put("consNum20101", i);
            m.put("effectPq20101", i);
            m.put("effectAmt20101", i);
            m.put("consNum20102", i);
            m.put("effectPq20102", i);
            m.put("effectAmt20102", i);
            m.put("consNum20103", i);
            m.put("expectedAddAmt20103", i);
            m.put("consNum20104", i);
            m.put("expectedAddAmt20104", i);
            rowList.add(m);
        }
        excelTool = new HssfExcelTool("实体类（entity）数据 多级表头表格", 20, 20);
        titleData = excelTool.columnTransformer(titleList1, "id", "pid", "content", "fileName", "title");
        name = UUID.randomUUID().toString();
        start = System.currentTimeMillis();
        excelTool.exportExcel(titleData, rowList, "e://" + name + ".xls", true, false);
        System.out.println(System.currentTimeMillis() - start);
        excelTool = new SXssfExcelTool("实体类（entity）数据 多级表头表格", 20, 20);
        start = System.currentTimeMillis();
        excelTool.exportExcel(titleData, rowList, "e://" + name + ".xlsx", true, false);
        System.out.println(System.currentTimeMillis() - start);

    }

}
